package com.cyl.manager.pms.domain.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyl.manager.pms.domain.entity.Sku;
import com.cyl.manager.pms.domain.service.SkuDomainService;
import com.cyl.manager.pms.mapper.SkuMapper;
import com.cyl.manager.pms.req.SkuQueryReq;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * @author: lsh
 * @create: 2025-01-22 14:50
 **/
@Service
public class SkuDomainServiceImpl extends ServiceImpl<SkuMapper, Sku> implements SkuDomainService {

    private final SkuMapper skuMapper;

    public SkuDomainServiceImpl(SkuMapper skuMapper) {
        this.skuMapper = skuMapper;
    }

    @Override
    public List<Sku> listByProductId(Long productId) {
        QueryWrapper<Sku> qw = new QueryWrapper<>();
        qw.eq("product_id", productId);
        return skuMapper.selectList(qw);
    }

    @Override
    public List<Sku> listByPage(SkuQueryReq query, Pageable page) {
        QueryWrapper<Sku> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(Objects.nonNull(query.getProductId()), Sku.COL_PRODUCT_ID, query.getProductId());
        queryWrapper.eq(StringUtils.isNotEmpty(query.getOutSkuId()), Sku.COL_OUT_SKU_ID, query.getOutSkuId());
        queryWrapper.eq(Objects.nonNull(query.getPrice()), Sku.COL_PRICE, query.getPrice());
        return skuMapper.selectList(queryWrapper);

    }
}
